Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
Google Scripts "Utilities.formatDate" does nothing with the time zone parameter

This 2 lines generate the same output:

Logger.log(Utilities.formatDate(new Date(), "ET", "yyyy-MM-dd'T'HH:mm:ss'Z'"));
Logger.log(Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'"));

Output:

2:20:37 PM Info -> 2022-01-26T19:20:37Z
2:20:37 PM Info -> 2022-01-26T19:20:37Z

Doesn't matter the input, is always converting the date to UTC (probably), this makes impossible to print the correct date and time.

What is the correct way to format a date-time in Google Scripts?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

"ET" is not an accepted time zone name.

For that you would use 'America/New_York'.

Apps Script's documentation doesn't call that out, which can be frustrating to non-developers. Here is the list of all the timeZone ids

Also, by putting the '' around the Z, it treats it as a string and just returns the date with a Z. I know that is what is in the example on the apps script page, but it is wrong.

Try this:

Logger.log(Utilities.formatDate(new Date(), "America/New_York", "yyyy-MM-dd'T'HH:mm:ss z"));
Logger.log(Utilities.formatDate(new Date(), "America/New_York", "yyyy-MM-dd'T'HH:mm:ss Z"));
Logger.log(Utilities.formatDate(new Date(), "America/Los_Angeles", "yyyy-MM-dd'T'HH:mm:ss z"));
Logger.log(Utilities.formatDate(new Date(), "America/Los_Angeles", "yyyy-MM-dd'T'HH:mm:ss Z"));
Logger.log(Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss Z"));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda